package cn.repository;

import cn.entity.Article;
import cn.entity.User;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.UUID;

/**
 * @author m on 2023/1/28
 * Description:
 */
public interface ArticleRepository extends JpaRepository<Article, UUID> {

    List<Article> findArticlesByUser(User user);
    List<Article> findAllByOrderByCreateTimeDesc(Pageable page);

    //模糊查找 昵称/标题
    @Query("select a from Article a inner join a.user as u  where a.title like concat('%',:kw,'%') or u.nickName like concat('%',:kw,'%') ")
    List<Article> findByQuery(@Param("kw") String kw);
}
